﻿//using System;
//using System.Collections.Generic;
//using System.Text;
//using DCRF.Common.Core;
//using DCRF.Common.Primitive;
//using DCRF.Common.Interface;
//using System.Web.Hosting;
//using System.Web;
//using System.IO;
//using System.Reflection;
//using DCRF.Common.Helper;
//using System.Collections;
//using System.Web.Caching;
//using DCRF.Common.Definition;

//namespace DCRF.BaseBlocks
//{
//    /// <summary>
//    /// This Block provides a virtual path for asp.net pages
//    /// Its used to lookup controls (ascx) that are compiled as embedded resource in other
//    /// DCRF Blocks
//    /// </summary>
//    public class VPathProvider : BlockBase
//    {
//        private InnerVPathProvider inner = new InnerVPathProvider();

//        public VPathProvider(Guid id, IBlockWeb parent)
//            : base(id, parent)
//        {
//        }

//        public override BlockInfo BlockInfo
//        {
//            get
//            {
//                BlockInfo result = new BlockInfo();
//                result.BlockID = new CID("VPathProvider", new BlockVersion(1, 0, 0, 0), "DCRF");
//                return result;
//            }
//        }

//        //public override PlatformType Platform
//        //{
//        //    get
//        //    {
//        //        return PlatformType.Web;
//        //    }
//        //}

//        public override void InitBlock()
//        {
//            if (System.Web.HttpContext.Current != null)
//            {
//                HostingEnvironment.RegisterVirtualPathProvider(inner);
//            }
//        }

//        [BlockService]
//        public void RegisterVirtualFile(string path, Type t, string resourceName)
//        {
//            inner.Register(path, t, resourceName);
//        }

//    }

//    class InnerVPathProvider : VirtualPathProvider
//    {
//        //key is path and value is an array of two objects (one is type and second is resourceName)
//        private Hashtable data = new Hashtable();

//        private string getAppResourcePath(string virtualPath)
//        {
//            foreach (string key in data.Keys)
//            {
//                if (virtualPath.EndsWith(key.Substring(1))) return key;
//            }

//            return null;
//        }

//        public void Register(string path, Type type, string resourceName)
//        {
//            data.Add(path, new object[] { type, resourceName });
//        }

//        public override bool FileExists(string virtualPath)
//        {
//            return (null != getAppResourcePath(virtualPath) ||
//                    base.FileExists(virtualPath));
//        }

//        public override VirtualFile GetFile(string virtualPath)
//        {
//            if (getAppResourcePath(virtualPath) != null )
//            {
//                string key = getAppResourcePath(virtualPath);

//                object[] obj = data[key] as object[];

//                return new VFile(obj[0] as Type, obj[1].ToString(), virtualPath);
//            }
//            else
//            {
//                return base.GetFile(virtualPath);
//            }
//        }

//        public override CacheDependency
//               GetCacheDependency(string virtualPath,
//               IEnumerable virtualPathDependencies,
//               DateTime utcStart)
//        {
//            if (getAppResourcePath(virtualPath) != null)
//            {
//                return null;
//            }
//            else
//            {
//                return base.GetCacheDependency(virtualPath,
//                       virtualPathDependencies, utcStart);
//            }
//        }
//    }

//    class VFile : VirtualFile
//    {
//        private Type type = null;
//        private string resourceName = null;

//        public VFile(Type t, string res, string path): base(path)
//        {
//            type = t;
//            resourceName = res;
//        }

//        public override Stream Open()
//        {
//            return type.Assembly.GetManifestResourceStream(resourceName);
//        }
//    }


//}
